package com.lbs.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author Administrator
 * @date 2021/5/19 16:32
 * @description
 **/
@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String username = request.getParameter("username");
        String password = request.getParameter("password");
        HttpSession session = request.getSession();

        if ("admin".equals(username)&&"123456".equals(password)){
            session.setAttribute("admin","admin");
            request.getRequestDispatcher("queryStu.do").forward(request,response);
        }else {
            session.setAttribute("msg","用户名或密码错误，请重新输入！");
            response.sendRedirect("login.jsp");
        }

    }
}
